﻿using System;
using QDT.Web.Admin.Code.Job;
using Quartz;

namespace QDT.Web.Admin
{
    public class QuartzManager
    {
        public static void Run(IScheduler scheduler)
        {
            CarryQuerySchedule(scheduler);
            AutoBidProjectSchedule(scheduler);
        }


        private static void CarryQuerySchedule(IScheduler scheduler)
        {
            IJobDetail carryQueryJob = JobBuilder.Create<CarryQueryJob>()
                    .WithIdentity("carryQueryJob", "carryQuery")
                    .Build();

            ITrigger carryQueryTrigger = TriggerBuilder.Create()
                .WithIdentity("carryQueryTrigger", "carryQuery")
                .StartAt(new DateTimeOffset(DateTime.Now.AddMinutes(10)))
                .WithSimpleSchedule(x => x
                    .WithIntervalInHours(1)
                    .RepeatForever())
                .Build();

            scheduler.ScheduleJob(carryQueryJob, carryQueryTrigger);
        }

        private static void AutoBidProjectSchedule(IScheduler scheduler)
        {
            IJobDetail autoBidProjectJob = JobBuilder.Create<AutoBidProjectJob>()
                    .WithIdentity("autoBidProjectJob", "autoBidProject")
                    .Build();

            ITrigger autoBidProjectTrigger = TriggerBuilder.Create()
                .WithIdentity("autoBidProjectTrigger", "autoBidProject")
                .StartAt(new DateTimeOffset(DateTime.Now.AddSeconds(5)))
                .WithSimpleSchedule(x => x
                    .WithIntervalInSeconds(30)
                    .RepeatForever())
                .Build();

            scheduler.ScheduleJob(autoBidProjectJob, autoBidProjectTrigger);
        }

    }
}